﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Brain.Windows.Docking
{
    public partial class DockingAreaControl : UserControl
    {
        public DockingAreaControl()
        {
            InitializeComponent();
        }

        protected override void OnCreateControl()
        {
            if (!DesignMode)
            {
                if (this.TopLevelControl is IDocker)
                {
                    IDocker docker = this.TopLevelControl as IDocker;
                    if (docker.DockManager == null)
                    {
                        docker.DockManager = new DockManager(this.TopLevelControl);
                    }
                    docker.DockManager.AddDockingArea(
                        new Rectangle(Bounds.X, Bounds.Y, Math.Min(Bounds.Width, 100), Math.Min(Bounds.Height, 100)),
                        this.Bounds);
                }
                this.Visible = false;

                for (int i = 0; i < this.TopLevelControl.Controls.Count; i++)
                {
                    Control c = this.TopLevelControl.Controls[i];
                    if (c.Bounds.IntersectsWith(this.Bounds) && c is DockControl)
                    {
                        DockControl con = c as DockControl;
                        con.Dock(this.Bounds);
                    }
                }
            }
            
            base.OnCreateControl();
        }
    }
}
